<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
class SelfPromise {
    #resolveCallback = null

    constructor(executor) {
        executor(val => {
            // resolve 函数的操作
            this.#resolveCallback && this.#resolveCallback(val)
        }, val => {
            // reject 函数的操作
        })
    }

    then(callback) {
        this.#resolveCallback = callback
        return this
    }

    catch() {
        return this
    }
}

new SelfPromise((resolve) => {
    setTimeout(() => resolve('success'), 2000)
}).then(res => {
    console.log(res)
})

</script>
</body>
</html>
